package com.chinanet.netelementmodel;


import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.HSSWebService;

import java.util.HashMap;
import java.util.Map;
/**
 * ZX_HSS_Query_URS_Imp
 * 中兴IMS-HSS网元-1、查询用户的注册状态
 * @author zyd
 */
public class ZX_HSS_Query_URS_Imp implements WorkInterFace {

	@Override
	public String getName() {
		return "查询用户的注册状态";
	}

	@Override
	public String getDesciption() {
		return "";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in = new Attr[1];
//		in[0] = new Attr("tbIpAddress", "跳板机的ip地址", AttrType.TYPE_String, true);
//		in[1] = new Attr("tbUsername", "跳板机登录用户名", AttrType.TYPE_String, true);
//		in[2] = new Attr("tbPassword", "跳板机登录密码", AttrType.TYPE_String, true);
//		in[3] = new Attr("switchboardIpAddress", "交换机的ip地址", AttrType.TYPE_String, true);
//		in[4] = new Attr("switchboardUsername", "交换机登录用户名", AttrType.TYPE_String, true);
//		in[5] = new Attr("switchboardPassword", "交换机登录密码", AttrType.TYPE_String, true);
		in[0] = new Attr("command", "查询指令", AttrType.TYPE_String, true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[3];
		out[0] = new Attr("PUI", "PUI", AttrType.TYPE_Int, true);
		out[1]=new Attr("regstatus","用户的注册状态",AttrType.TYPE_String,true);
		out[2]=new Attr("log","日志",AttrType.TYPE_String,true);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		AttrsIn attrsIn=new AttrsIn();
		HSSWebService webService=new HSSWebService();
		Map<String,Object> map=new HashMap<String, Object>();
		//Get soapxml
		attrsIn.setClientSysName("HSSSubscriberPUIProfile");
		attrsIn.setFunctionName("QryPUIInfo");
		attrsIn.setRequestMessage("<PUI>"+ data.get("command")+"</PUI>");
		String returnXml=webService.WebServiceInit(attrsIn);
		int result=Integer.parseInt(webService.getPattern("REGSTATUS", returnXml));
		if(result== 1){
			map.put("regstatus","REGISTERED");
		}else if(result==2){
			map.put("regstatus","UNREGISTERED");
		}else{
			map.put("regstatus","NOTREGISTERED");
		}
		map.put("log",returnXml);
		return map;
	}

}
